#include <stdio.h>
#include "jni.h"

JNIEXPORT void JNICALL Java_oop_other_NativeDemo_helloWorld() {
    printf("Hello, World!\n");
}

JNIEXPORT void JNICALL Java_oop_other_NativeDemo_helloWorld2() {
    printf("Hello, World2!\n");
}

JNIEXPORT jint JNICALL Java_oop_other_NativeDemo_add(JNIEnv *env, jobject obj, jint a, jint b) {
    printf("a: %ld, b: %ld\n", a, b);
    return a + b;
}

void printObjectInfo(JNIEnv *env, jobject obj) {
    jclass cls = (*env)->GetObjectClass(env, obj);
    printf("jclass address: %p\n", cls);
    jmethodID toStringMethod = (*env)->GetMethodID(env, cls, "toString", "()Ljava/lang/String;");
    printf("jmethodID address: %p\n", toStringMethod);
    jstring str = (jstring) (*env)->CallObjectMethod(env, obj, toStringMethod);
    printf("jstring address: %p\n", str);

    const char *cstr = (*env)->GetStringUTFChars(env, str, NULL);
    printf("Object Info: %s\n", cstr);
    (*env)->ReleaseStringUTFChars(env, str, cstr);
}

JNIEXPORT void JNICALL Java_oop_other_NativeDemo_printObjectInfo(JNIEnv *env, jobject obj) {
    printObjectInfo(env, obj);
}